﻿using System.IO;
using System.Web;
using System.Web.Hosting;

namespace Inovout.Web
{
    public class ShareingVirtualFile : VirtualFile
    {
        private string virtualPath;
        public ShareingVirtualFile(string virtualPath)
            : base(virtualPath)
        {
            this.virtualPath = virtualPath;
        }

        public override Stream Open()
        {
            if (!(HttpContext.Current == null))
            {
                if (HttpContext.Current.Cache[virtualPath] == null)
                {
                    HttpContext.Current.Cache.Insert(virtualPath, ReadResource(virtualPath));
                }
                return (Stream)HttpContext.Current.Cache[virtualPath];
            }
            else
            {
                return ReadResource(virtualPath);
            }
        }

        private static Stream ReadResource(string embeddedFileName)
        {
            return null;
            //string resourceFileName = VirtualPathUtility.GetFileName(embeddedFileName);
            //Assembly assembly = Assembly.GetExecutingAssembly();
            //return assembly.GetManifestResourceStream(MasterPageVirtualPathProvider.VirtualPathProviderResourceLocation + "." + resourceFileName);
        }
    }
}
